﻿using System.Diagnostics.CodeAnalysis;

namespace Modules.System.Role
{
    /// <summary>
    /// 角色与用户关系数据比较器
    /// </summary>
    public class SysUserRoleComparer : IEqualityComparer<SysUserRole>
    {
        public bool Equals(SysUserRole? x, SysUserRole? y)
        {
            if (x == null && y == null)
                return true;
            else if (x == null || y == null)
                return false;
            else if (x.RoleId == y.RoleId && x.UserId == y.UserId)
                return true;
            else
                return false;
        }

        public int GetHashCode([DisallowNull] SysUserRole obj)
        {
            return $"{obj.RoleId}{obj.UserId}".GetHashCode();
        }
    }
}